// import { RESPONSE_CODE } from "@/common/config";
// import { handleAgreementPrivacy, handleAgreementService } from "@/common/service";
// import { IPrivacyResponse, IResponseSuccess } from "@/typing";
import { RichText } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { useEffect, useState } from "react";
import { useStore } from '@/store';
import { observer } from 'mobx-react-lite';
import '@tarojs/taro/html5.css'
import { handleInitAgreementPrivacy, handleInitAgreementService } from "@/common/util";


const Privacy:React.FC=()=>{
    const privacyType = 'blogger'
    const {agreementsStore} =useStore()
    
    const [privacyContent,setPrivacyContent]=useState<Array<any>>([])
    
    const handleInitPrivacy=async()=>{
        
        const currentInstance = Taro.getCurrentInstance();
        if(currentInstance && currentInstance.router){
            const routerParams = currentInstance.router.params
            const pageEntry = routerParams.pageEntry;
            if(pageEntry === 'service'){
                Taro.setNavigationBarTitle({title:'服务协议'})
                // const serviceRes = await handleInitAgreementService()
                if(agreementsStore.serviceContent.length > 0){
                    setPrivacyContent(agreementsStore.serviceContent)
                }else{
                    const serviceRes = await handleInitAgreementService(privacyType)
                    setPrivacyContent(serviceRes.content)
                }
               
               
            }else if(pageEntry === 'privacy'){
                Taro.setNavigationBarTitle({title:'隐私政策'})
                if(agreementsStore.privacyContent.length >0){
                    setPrivacyContent(agreementsStore.privacyContent)
                }else{
                    const privacyRes = await handleInitAgreementPrivacy(privacyType)
                    setPrivacyContent(privacyRes.content)
                }
             
                
               
                
            }
        }
    }
    useEffect(() => {
      
        handleInitPrivacy()
        return () => {
            
        };
    }, []);
    return <>
   
    <RichText nodes={privacyContent}></RichText>
   
    </>
}

export default observer(Privacy) 